package xyz.jangle.date;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
/**
 * 获取当前时间的字符串格式数据
 * @author Administrator
 *
 */
public class DateTimeM {

	public static void main(String[] args) {
		
		System.out.println(LocalDateTime.now());
		
		LocalTime now = LocalTime.now();
		int hour = now.getHour(); // 获取小时（24小时制）
		int minute = now.getMinute(); // 获取分钟
		String hourStr = hour < 10?"0"+hour:""+hour;
		String minuteStr = minute<10?"0"+minute:""+minute;
		String code = hourStr + minuteStr;
 
        System.out.println("当前时间：" + hourStr + "时 " + minuteStr + "分");
        System.out.println(code);
        System.out.println(Integer.valueOf(code) > Integer.valueOf("0700") && Integer.valueOf(code) < Integer.valueOf("0800"));
        System.out.println(Integer.valueOf(code) > Integer.valueOf("1700") && Integer.valueOf(code) < Integer.valueOf("1800"));
        
        System.out.println("-----------------");
        
        // 格式化时间为字符串
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HHmm");
        String timeString = now.format(formatter);
        // 输出时间字符串
        System.out.println("当前时间是: " + timeString);
        
        
        LocalDateTime now2 = LocalDateTime.now();
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String time2 = now2.format(formatter2);
        System.out.println(time2);
	}

}
